/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package war2100.game.items;

import org.newdawn.slick.geom.Vector2f;
import war2100.game.items.ammo.Ammo;
import war2100.game.states.GameplayState;

/**
 *
 * @author efischer
 */
public class Weapon extends Item {
	private Ammo ammo;
	private int ammoCount;
	
	private long lastFired;
	private long reloadSpeed;
	
	public Weapon(GameplayState gs)
	{
		super(gs);
		setLifeTime(-1);
	}
	
	public void shoot(Vector2f pos, Vector2f dir)
	{
		if(this.getOwner() == null)
			return;
		
		if(this.lastFired + reloadSpeed > System.currentTimeMillis())
			return;
		
		if(getAmmoCount() == 0)
		{
			//Keine Munition mehr - Sound? Waffe entfernen?
			return;
		}
		
		this.lastFired = System.currentTimeMillis();
		
		if(getAmmoCount() != -1)
			setAmmoCount(getAmmoCount() - 1);
		
		Ammo ammo = getAmmo().copy();
		ammo.setPosition(pos);
		ammo.setDirection(dir);
		getGameState().getShoots().add(ammo);
	}
	
	/**
	 * @return the ammo
	 */
	public Ammo getAmmo() {
		return ammo;
	}

	/**
	 * @param ammo the ammo to set
	 */
	public void setAmmo(Ammo ammo) {
		this.ammo = ammo;
	}

	/**
	 * @return the ammoCount
	 */
	public int getAmmoCount() {
		return ammoCount;
	}

	/**
	 * @param ammoCount the ammoCount to set
	 */
	public void setAmmoCount(int ammoCount) {
		this.ammoCount = ammoCount;
	}

	/**
	 * @return the lastFired
	 */
	public long getLastFired() {
		return lastFired;
	}

	/**
	 * @param lastFired the lastFired to set
	 */
	public void setLastFired(long lastFired) {
		this.lastFired = lastFired;
	}

	/**
	 * @return the reloadSpeed
	 */
	public long getReloadSpeed() {
		return reloadSpeed;
	}

	/**
	 * @param reloadSpeed the reloadSpeed to set
	 */
	public void setReloadSpeed(long reloadSpeed) {
		this.reloadSpeed = reloadSpeed;
	}
	
}
